package utils

import (
	"crypto/md5"
	"fmt"
	"time"

	"github.com/golang-jwt/jwt/v5"
)

func GetMD5(data string) string {
	datas := []byte(data + SALT)
	hash := md5.Sum(datas)
	return fmt.Sprintf("%x", hash)
}

func GetToken(size int) (string, int) {
	fmt.Println("开始获取token")
	t := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"exp": jwt.NewNumericDate(time.Now().Add(time.Duration(size) * time.Second)),
	})
	token, err := t.SignedString([]byte(SALT))

	fmt.Println("token: " + token)
	if err != nil {
		fmt.Println("token 生成失败了")
		fmt.Println(err)
		return "", ERROR_TOKEN
	}
	return token, SUCCESS_TOKEN
}
